<template>
	<view class="loginOuter">
		<image class="avatar" src="../../static/logo.png" mode=""></image>
		<form class="userInfo">
			<input type="text" v-model="userInfo.mobile" placeholder="请输入手机号码或账号">
			<input :type="inputType" class="passwordInp" v-model="userInfo.password" placeholder="请输入密码">
			<image @click="eyeChange" class="eye" :src="eyeImg" mode=""></image>
		</form>
		<view class="forget">
			忘记密码?
		</view>
		<view :class="userInfo.password === ''?'loginZ':'loginZ1'" @click="loginTo">
			登录
		</view>
		<view class="aggrement">
			登录即代表你同意<span>用户协议</span>和<span>隐私协议</span>
		</view>
		<view class="loginBtn">
			<view class="loginBtn_l">
				验证码登录
			</view>
			<view class="loginBtn_r">
				注册
			</view>
		</view>

	</view>
</template>

<script>
	import {
		loginApi
	} from '../../api/paiModule/login.js'
	export default {
		data() {
			return {
				userInfo: {
					mobile: '',
					password: '',
					method: "user.login",
				},
				inputType: 'password',
				eyeImg: '../../static/images/iconImg/yjb.png'
			};
		},
		methods: {
			async loginTo() {
				if (this.userInfo.mobile === '' || this.userInfo.password === '') {
					alert('用户名或密码不可为空')
				} else {
					const {
						data: res
					} = await loginApi(this.userInfo)
					uni.setStorageSync('token', res.data)
					this.userInfo.mobile = '',
						this.userInfo.password = ''
					uni.reLaunch({
						url: '/pages/my/my'
					})
				}
			},
			// 改变眼睛
			eyeChange() {
				if (this.eyeImg === '../../static/images/iconImg/yjb.png') {
					this.eyeImg = '../../static/images/iconImg/yjk.png'
					this.inputType = 'text'
				} else if (this.eyeImg === '../../static/images/iconImg/yjk.png') {
					this.eyeImg = '../../static/images/iconImg/yjb.png'
					this.inputType = 'password'
				}
			}
		}
	}
</script>

<style lang="scss">
	.loginOuter {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		.avatar {
			height: 80px;
			width: 80px;
			margin-top: 20px;
		}

		.userInfo {
			width: 80%;
			margin-top: 20px;
			position: relative;

			input {
				border-bottom: 1px solid #e2e2e2;
				padding: 10px 0px 6px 6px;
				font-size: 14px;

				&:not(:last-child) {
					margin-bottom: 10px;
				}
			}

			.passwordInp {
				width: 100%;
				border: none;
				outline: none;
				border-bottom: 1px solid #e2e2e2;
				padding: 10px 0px 6px 6px;
				font-size: 14px;
			}

			.eye {
				width: 20px;
				height: 20px;
				position: absolute;
				right: 0;
				bottom: 6px;
			}


		}

		.forget {
			font-size: 12px;
			margin-top: 10px;
			color: #919191;
			margin-left: 66%;
		}

		.loginZ {
			width: 80%;
			background-color: #f7f7f7;
			text-align: center;
			padding: 10px 0;
			font-size: 14px;
			margin-top: 40px;
		}

		.loginZ1 {
			width: 80%;
			background-color: #000;
			color: #fff;
			text-align: center;
			padding: 10px 0;
			font-size: 14px;
			margin-top: 40px;
		}

		.aggrement {
			font-size: 12px;
			color: #919191;

			span {
				display: inline-block;
				margin: 0 6px;
				color: red;
				margin-top: 10px;
			}
		}

		.loginBtn {
			width: 80%;
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 14px;
			margin-top: 20px;
		}

	}
</style>